package com.keyware.kd.service.impl.jurisdiction;

import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.druid.util.StringUtils;
import com.keyware.kd.controller.jurisdiction.MenuController;
import com.keyware.kd.repository.entity.NotOperableMenu;
import com.keyware.kd.repository.mybatis.itf.NotOperableMenuMapper;
import com.keyware.kd.service.itf.jurisdiction.NotOperableMenuService;
import com.keyware.kd.utils.Constant;
import com.keyware.utils.IdGenerator;

@Service("notOperableMenuService")
public class NotOperableMenuServiceImpl implements NotOperableMenuService {

	public static Logger logger = Logger.getLogger(MenuController.class);
	
	@Autowired
	private NotOperableMenuMapper notOperableMenuMapper;

	@Override
	public int insert(NotOperableMenu record) {
		return notOperableMenuMapper.insert(record);
	}

	@Override
	public int insertSelective(NotOperableMenu record) {
		return notOperableMenuMapper.insertSelective(record);
	}

	@Override
	public int deleteAll() {
		return notOperableMenuMapper.deleteAll();
	}
	
	@Transactional
	@Override
	public HashMap<String, String> insertNotOperableMenu(String menuIds, String menuNames) {
		String[] menuId  = menuIds.split(",");
		String[] menuName = {};
		if(!StringUtils.isEmpty(menuNames)){
			 menuName  = menuNames.split(",");
		}
		HashMap<String, String> map = new HashMap<String, String>();
//		List<NotOperableMenu> menuList = new ArrayList<NotOperableMenu>();
		try {
			notOperableMenuMapper.deleteAll();
			for (int i = 0; i < menuId.length; i++) {
				NotOperableMenu menu = new NotOperableMenu();
				menu.setId(IdGenerator.uuid32());
				menu.setMenuId(menuId[i]);
				if(!StringUtils.isEmpty(menuNames)){
					menu.setMenuName(menuName[i]);
				}
//				menuList.add(menu);
				notOperableMenuMapper.insertSelective(menu);
			}
			//notOperableMenuService.insertMenuList(menuList);
			map.put("code", "1");
			map.put("message", "操作成功");
		} catch (Exception e) {
			logger.error(e);
			map.put("code", "0");
			map.put("message", Constant.ERROE_MESSAGE);
		}
		return map;
	}

	@Override
	public List<NotOperableMenu> selectnotOperableMenuAll() {
		return notOperableMenuMapper.selectnotOperableMenuAll();
	}

}
